#ifndef __MAIN_HEADER__
#define __MAIN_HEADER__
#include <my_header.h>
#include "Arr.h"
#include "Queue.h"
#include "dirStack.h"
#include "func.h"
#include "jiekou.h"
#include"plog.h"
typedef enum{
    CD,
    LS,
    PUTS,
    GETS,
    REMOVE,
    PWD,
    MKDIR,
    RMDIR,
    FAILURE
}Type;      //枚举，用于标志文件类型

typedef struct{
    int type;
    int length;
    char data[1024];

}train_t;       //TLV协议使用的数据类型

//服务端采用线程池的写法，所有方式都要围绕线程池
typedef struct{
    //子线程的属性，数量
    Arr_t arr;
    
    //初始化队列
    Queue_t queue;
    
    //互斥锁，访问主线程传递的工作是个共享变量，需要互斥锁
    pthread_mutex_t mutex;

    //条件变量
    pthread_cond_t cond;
    
    //退出标志，用于优雅退出
    int flag;
}Main_thread;

typedef struct{
    char fake_path[1024];
    char absolute_path[1024];
}Path;


int Tcp_connect(char *fd,char *port);

int init_all(Main_thread *m_thread,int workNum);

int epoll_add(int epfd,int sockfd);

int makeworker(Main_thread *m_thread);

//int use_puts(int netfd);

//int use_pwd(dirStack_t *st, char *P);
int recvn(int netfd,void *buf,int length);
int recv_command(int netfd);
int send_Feedback_Good(int netfd);

int send_Feedback_bad(int netfd);

int Recv_and_Push_stack(dirStack_t *st, int netfd);

int rebuild_Stack(dirStack_t *st , char *fake_path);
//int use_gets(int netfd, char *filename,char *username,MYSQL *mysql,dirStack_t * st,file_t *file,char *result);
int use_gets(int netfd, char *filename,file_t *file);
void *work(void *arg);
int use_remove(dirStack_t * stack, int netfd, MYSQL *db, char *username);

int get_id1(MYSQL *mysql,char *username,char *send_back,char *result,char *id);
int get_id(MYSQL *mysql,char *username,char *send_back,char *result,char *id);
int get_path(MYSQL *mysql,char *username,char *send_back,char *result,char *path);
int use_pwd(dirStack_t *st,MYSQL *mysql,char *send_back);
//int use_gets(int netfd,char *filename);
int user_puts(dirStack_t *dirStack,char* user,int netfd,MYSQL *db , char *server_dir,file_t *file);
int use_cd(dirStack_t *st, MYSQL *mysql, char *result, char *username, char *send_back);
int makedir(dirStack_t *st,MYSQL *mysql,const char *userName,const char *dirName,char *result);
int removeDir(dirStack_t *st,MYSQL *mysql,const char *userName,const char *dirName,char *result);
void generate_ciphertext(char *salt,char *passwd,char *ciphertext);
void  generate_salt(char *salt);
int userRegister(MYSQL*db,int netfd,user_t *user);
int userLogin(MYSQL*db,int netfd,user_t *user);
#endif

